//
//  SLVIPMonthButton.m
//  StarLight
//
//  Created by Duke.wu on 16/6/6.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLVIPMonthButton.h"

@interface SLVIPMonthButton ()

@property (nonatomic, strong) UILabel *monthLabel;

@property (nonatomic, strong) UILabel *priceLabel;

@end

@implementation SLVIPMonthButton

- (instancetype)init{
  if (self == [super init]) {
    [self addSubview:self.monthLabel];
    [self addSubview:self.priceLabel];
    [self addConstrains];
    [self addObservers];
  }
  return self;
}

- (void)addConstrains{
  self.backgroundColor = [UIColor whiteColor];
  
  [self.monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.mas_centerY);
    make.centerX.equalTo(self);
  }];
  [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(self);
    make.top.equalTo(self.monthLabel.mas_bottom).offset(10);
  }];
}

- (void)addObservers{
  
  @weakify(self)
  [RACObserve(self, selected) subscribeNext:^(NSNumber *select) {
    @strongify(self)
    self.backgroundColor = select.boolValue == 1 ? SLYellowColor : [UIColor whiteColor];
    self.monthLabel.textColor = select.boolValue == 1 ? [UIColor whiteColor] : [UIColor lightGrayColor];
    self.priceLabel.textColor = select.boolValue == 1 ? [UIColor whiteColor] : [UIColor lightGrayColor];
  }];
}


- (void)configWithModel:(SLVIPPriceModel *)model{
  self.monthLabel.text = [NSString stringWithFormat:@"%ld个月",(long)model.month];
  self.priceLabel.text = [NSString stringWithFormat:@"售价 %.2f元",model.price];
}

- (UILabel *)monthLabel{
  if (!_monthLabel) {
    _monthLabel = [UILabel labelwithBoldFontSize:15 textColor:[UIColor lightGrayColor] text:@"Month"];
    _monthLabel.textAlignment = NSTextAlignmentCenter;
  }
  return _monthLabel;
}

- (UILabel *)priceLabel{
  if (!_priceLabel) {
    _priceLabel = [UILabel labelwithBoldFontSize:10 textColor:[UIColor lightGrayColor] text:@"售价"];
    _priceLabel.textAlignment = NSTextAlignmentCenter;
  }
  return _priceLabel;
}


@end






